<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Huiyuan extends CI_Controller {	
	 function __construct()
	 {
	  	parent::__construct();
	  	$this->load->helper('url');
	  //	$this->load->database();
	  	$this->load->model('TB_Huiyuan');
	 }
	 function index()
	{
		$this->RefreshHuiyuan();
	//	$data["results"]=$this->TB_User->GetAllUser();
	//	$this->load->view("view_user",$data);
	}
	 
	function Insert()
	{
		$data=$this->do_upload();
		$hyEnt=array("hy_name"=>$_POST["hy_name"],
		"hy_sex"=>$_POST["hy_sex"],
		"hy_birthday"=>$_POST["hy_birthday"],
		"hy_IDcard"=>$_POST["hy_IDcard"],
		"hy_hukou"=>$_POST["hy_hukou"],
		"hy_huiyuan_no"=>$_POST["hy_huiyuan_no"],
		"hy_indate"=>$_POST["hy_indate"],
		"hy_clientname"=>$_POST["hy_clientname"],
		"hy_duty"=>$_POST["hy_duty"],
		"hy_photo"=>$data['upload_data']['file_name'],
		"hy_meno"=>$_POST["hy_meno"]);
		$this->TB_Huiyuan->insert($hyEnt); 
		$this->RefreshHuiyuan();
	}
	function Update()
	{
		$data=$this->do_upload();
		$imgpath=$data['upload_data']['file_name'];
		if($imgpath=="")
		{
			$NewsEntity=$this->TB_News->get_NewsByClassID($_POST["NewsID"]);
			$imgpath=$NewsEntity[0]->ImgPath;
		}
		$hyEnt=array("ID"=>$_POST["ID"],
		"hy_name"=>$_POST["hy_name"],
		"hy_sex"=>$_POST["hy_sex"],
		"hy_birthday"=>$_POST["hy_birthday"],
		"hy_IDcard"=>$_POST["hy_IDcard"],
		"hy_hukou"=>$_POST["hy_hukou"],
		"hy_huiyuan_no"=>$_POST["hy_huiyuan_no"],
		"hy_indate"=>$_POST["hy_indate"],
		"hy_clientname"=>$_POST["hy_clientname"],
		"hy_duty"=>$_POST["hy_duty"],
		"hy_photo"=>$imgpath,
		"hy_meno"=>$_POST["hy_meno"]);
		$this->TB_Huiyuan->Update($hyEnt); 
		$this->RefreshHuiyuan();
	}
	public function delete()
	{
		$this->TB_Huiyuan->delete($_GET["ID"]); 
		$this->RefreshHuiyuan();
	}
	function GetAllHuiyuan()
	{
		return 	$this->TB_Huiyuan->GetAllHuiyuan();
	}
	function GetHuiyuanByID($ID)
	{
		return 	$this->TB_Huiyuan->GetHuiyuanByID($ID);
	}
	function GetHuiyuanByNo($huiyuan_no)
	{
		return 	$this->TB_Huiyuan->GetHuiyuanByNo($huiyuan_no);
	}
	function RefreshHuiyuan()
	{
		$data["results"]=$this->GetAllHuiyuan();
		$this->load->view("view_huiyuan",$data);
	}
	function do_upload()
	 {
	 	  //$data=$this->do_upload();
		  $config['upload_path'] = getcwd().'./uploads/';
		  $config['allowed_types'] = 'gif|jpg|png';
		  $config['max_size'] = '1000';
		  $config['max_width']  = '1024';
		  $config['max_height']  = '768';
		  $config['overwrite']=true;
 	   	  $config['file_name']=date('ymdhis');

		  $this->load->library('upload', $config);
		  $this->upload->initialize($config);
		  $this->upload->do_upload();
		  return  $data = array('upload_data' => $this->upload->data());
	 }
}